package com.gjy.design.proxy.jdkp;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-11-10 10:44:56
 */
public class LoggingInvocationHandler implements InvocationHandler {

    private final Object target;

    public LoggingInvocationHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        long start = System.currentTimeMillis();
        Object result = method.invoke(target, args);   // 调用真实对象
        long end = System.currentTimeMillis();
        System.out.println("[JDKProxy] method=" + method.getName() + ", cost=" + (end - start) + " ms");
        return result;
    }
}

